package com.msw.axon.model.optimize;

import com.msw.axon.model.Student;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;


/**
 * 学习 EntityGraph
 */

@Entity
@Table(name = "")
@NamedEntityGraphs({
        @NamedEntityGraph(name = "account.all",
                attributeNodes = {//attributeNodes 来定义需要懒加载的属性
                        @NamedAttributeNode("student"), @NamedAttributeNode("staff"),//无延伸
                        @NamedAttributeNode(value = "roles",//要懒加载roles属性中的pages元素
                                subgraph = "pages"),
                },
                subgraphs = {//subgraphs 来定义关联对象的属性
                        @NamedSubgraph(name = "pages",//一层延伸
                                attributeNodes = @NamedAttributeNode("pages")),
                        @NamedSubgraph(name = "role",//两层延伸
                                attributeNodes = @NamedAttributeNode(
                                        value = "role",
                                        subgraph = "pages"))})})
public class Account {

    //@OneToOne
    //@JoinColumn(name = "")
    //private Staff staff;

    @Id
    private String id;

    @OneToOne
    @JoinColumn(name = "")
    private Student student;

    @Column
    private String username;

    @Column
    private String password;

    @ManyToMany(cascade = CascadeType.REFRESH)
    @JoinTable(name = "",
            joinColumns = {@JoinColumn(name = "accounts", referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "roles", referencedColumnName = "id")})
    @OrderBy(value = "id DESC")
    private Set<Role> roles = new HashSet<>();

    //@OneToMany(mappedBy = "account")
    //private Set<AccountPrivilege> accountPrivileges = new HashSet<>();

}
